package programmercarl.动态规划.C32;

class Solution {
    public int maxProfit(int[] prices) {
        if (prices == null || prices.length == 0||prices.length == 1) {return 0;}
        int minPrice = prices[0];
        int maxProfit = 0;
        for (int i = 1; i < prices.length; i++) {
            maxProfit= Math.max(maxProfit, prices[i] - minPrice);
            if (prices[i] < minPrice) {
                minPrice = prices[i];
            }
        }
        return maxProfit;
    }
}